package com.ruoyi.project.system.user.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import com.ruoyi.framework.config.RuoYiConfig;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.project.system.menu.domain.Menu;
import com.ruoyi.project.system.menu.service.IMenuService;
import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.web.tRoominfo.domain.TRoominfo;
import com.ruoyi.project.web.tRoominfo.domain.TRoominfo2;
import com.ruoyi.project.web.tRoominfo.service.ITRoominfoService;

/**
 * 首页 业务处理
 * 
 * @author ruoyi
 */
@Controller
public class IndexController extends BaseController
{
    @Autowired
    private IMenuService menuService;
    
    @Autowired
	private ITRoominfoService tRoominfoService;

    @Autowired
    private RuoYiConfig ruoYiConfig;

    // 系统首页
    @GetMapping("/index")
    public String index(ModelMap mmap)
    {
        // 取身份信息
        User user = getSysUser();
        // 根据用户id取出菜单
        List<Menu> menus = menuService.selectMenusByUser(user);
        mmap.put("menus", menus);
        mmap.put("user", user);
        mmap.put("copyrightYear", ruoYiConfig.getCopyrightYear());
        mmap.put("demoEnabled", ruoYiConfig.isDemoEnabled());
        return "index";
    }

    // 系统介绍
    @GetMapping("/system/main")
    public String main(ModelMap mmap)
    {
    	TRoominfo tRoominfo= new TRoominfo();
    	tRoominfo.setFjqyzt("启用");
    	List<TRoominfo> tRoominfoList = tRoominfoService.selectTRoominfoList(tRoominfo);
    	
    	List<TRoominfo2> tRoominfoList2 = new ArrayList<TRoominfo2>();
    	TRoominfo oldTRoominfo = new TRoominfo();
    	Boolean hhzt = true;
    	for(int i =0;i<tRoominfoList.size();i++){
    		if(hhzt){
    			oldTRoominfo = tRoominfoList.get(i);
    			hhzt = false;
    		}else{
    			if(oldTRoominfo.getHh().equals(tRoominfoList.get(i).getHh())){
    				TRoominfo2 tRoominfo2 = new TRoominfo2();
    				tRoominfo2.setId(oldTRoominfo.getId());
    				tRoominfo2.setFjh(oldTRoominfo.getFjh());
    				tRoominfo2.setKssj(oldTRoominfo.getKssj());
    				tRoominfo2.setZt(oldTRoominfo.getZt());
    				
    				tRoominfo2.setId2(tRoominfoList.get(i).getId());
    				tRoominfo2.setFjh2(tRoominfoList.get(i).getFjh());
    				tRoominfo2.setKssj2(tRoominfoList.get(i).getKssj());
    				tRoominfo2.setZt2(tRoominfoList.get(i).getZt());
    				tRoominfoList2.add(tRoominfo2);
    				
    				oldTRoominfo = new TRoominfo();
    				
    			}
    			hhzt = true;
    		}
    	}
    	
    	
    	
    	
    	mmap.put("tRoominfoList2", tRoominfoList2);
        mmap.put("version", ruoYiConfig.getVersion());
        return "main";
    }
}
